package com.agile.major.repository;

import com.agile.major.domain.BaseDepartment;
import com.agile.major.domain.BaseMajor;
import com.agile.major.domain.BaseTeacher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;


/**
 * Spring Data JPA repository for the BaseMajor entity.
 */
@SuppressWarnings("unused")
@Repository
public interface BaseMajorRepository extends JpaRepository<BaseMajor, Long> {

    //根据专业带头人或专业负责人查找专业
    @Query("select a from BaseMajor a where (a.chargeTeacher=?1 or a.leaderTeacher=?1) ")
    Page findMajorsByChargeTeacherOrLeaderTeacher(BaseTeacher teacher, Pageable page);


    //按二级院查找专业
    Page findMajorsByDepartment(BaseDepartment department, Pageable page);

    //既是专业带头人又是二级院长查找专业
    @Query("select a from BaseMajor a where (a.chargeTeacher=?1 or a.leaderTeacher=?1 or a.department=?2) ")
    Page findMajorsByDepAndTeacher(BaseTeacher teacher, BaseDepartment department, Pageable page);

}
